package uz.rt.plan;

import uz.rt.linac.ControlPoint;
import uz.rt.utils.Itemizable;

import java.util.ArrayList;
import java.util.Iterator;

public class Beam implements Itemizable<Double, ControlPoint>
{
    protected ArrayList<ControlPoint> cps = null;

    public Beam()
    {
        cps = new ArrayList<ControlPoint>();
    }

    public Beam(final ArrayList<ControlPoint> cps)
    {
        if (cps != null)
            this.cps = cps;
        else this.cps = new ArrayList<ControlPoint>();
    }

    public void add(final ControlPoint cp)
    {
        cps.add(cp);
    }

    public void edit(final Double cmu, final ControlPoint cp)
    {
        for (int i = 0; i < cps.size(); i++)
        {
            if (cps.get(i).getCmu() == cmu)
                cps.set(i, cp);
        }
    }

    public void removeByKey(final Double cmu)
    {
        Iterator<ControlPoint> itr = cps.iterator();
        while (itr.hasNext())
        {
            ControlPoint cp = itr.next();
            if (cp.getCmu() == cmu) itr.remove();
        }
    }

    public void removeValue(final ControlPoint cp)
    {
        Iterator<ControlPoint> itr = cps.iterator();
        while (itr.hasNext())
        {
            ControlPoint tcp = itr.next();
            if (tcp == cp) itr.remove();
        }
    }

    public int size()
    {
        return cps.size();
    }
}
